<?php
/******************************
 * EQdkp
 * Copyright 2002-2005
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * listitemdata.php
 * Began: Sun April 6, 2008
 *
 *
 ******************************/

define('EQDKP_INC', true);
$eqdkp_root_path = './';
include_once($eqdkp_root_path . 'common.php');

$user->check_auth('u_item_list');

//
// Item Values (unique items)
//

$sort_order = array(
    0 => array('item_name', 'item_name desc'),
    1 => array('item_level', 'item_level desc'),
    2 => array('dropped_from', 'dropped_from desc'),
    3 => array('item_jobs', 'item_jobs desc')
);

$current_order = switch_order($sort_order);

$u_list_items = 'listitemdata.php'.$SID.'&amp;';

$page_title = sprintf($user->lang['title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['listitemdata_title'];

$total_items = $db->num_rows($db->query('SELECT item_data_id FROM ' . ITEM_DATA_TABLE . ' GROUP BY item_name'));
$start = ( isset($_GET['start']) ) ? $_GET['start'] : 0;

$sql = 'SELECT item_data_id, item_name, item_jobs, item_level, dropped_from
        FROM '. ITEM_DATA_TABLE . '
        ORDER BY '.$current_order['sql']. '
        LIMIT '.$start.','.$user->data['user_ilimit'];

$listitems_footcount = sprintf($user->lang['listitems_footcount'], $total_items, $user->data['user_ilimit']);
$pagination = generate_pagination('listitemdata.php'.$SID.'&amp;o='.$current_order['uri']['current'], $total_items, $user->data['user_ilimit'], $start);

if ( !($items_result = $db->query($sql)) )
{
    message_die('Could not obtain item information', '', __FILE__, __LINE__, $sql);
}

while ( $item = $db->fetch_record($items_result) )
{
    $tpl->assign_block_vars('items_row', array(
        'ROW_CLASS' => $eqdkp->switch_row_class(),
        'NAME' => stripslashes($item['item_name']),
        'LEVEL' => $item['item_level'],
        'CLASS' => stripslashes($item['item_jobs']),
        'DROPPED_FROM' => stripslashes($item['dropped_from']),
        'U_VIEW_ITEM' => 'viewitemdata.php'.$SID.'&amp;' . URI_ITEM . '='.$item['item_data_id'])
    );
}
$db->free_result($items_result);

$tpl->assign_vars(array(
    'L_ITEM' => $user->lang['item'],
    'L_LEVEL' => $user->lang['level'],
    'L_CLASS' => $user->lang['class'],
    'L_DROPPED_FROM' => $user->lang['dropped_from'],

    'O_NAME' => $current_order['uri'][0],
    'O_ITEM_LEVEL' => $current_order['uri'][1],
    'O_ITEM_CLASS' => $current_order['uri'][3],
    'O_ITEM_DROPPED_FROM' => $current_order['uri'][2],

    'U_LIST_ITEMS' => $u_list_items,

    'START' => $start,
    'S_HISTORY' => $s_history,
    'LISTITEMS_FOOTCOUNT' => $listitems_footcount,
    'ITEM_PAGINATION' => $pagination)
);

$eqdkp->set_vars(array(
    'page_title'    => $page_title,
    'template_file' => 'listitemdata.html',
    'display'       => true)
);
?>
